home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earcd / grafica / ghostscript / 5.10 / data / viewpcx.ps < prev    next >
Text File  |  1997-05-02  |  4KB  |  134 lines

  1. %    Copyright (C) 1996 Aladdin Enterprises.  All rights reserved.
  2. %
  3. % This file is part of Ghostscript.
  4. %
  5. % Ghostscript is distributed in the hope that it will be useful, but
  6. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. % to anyone for the consequences of using it or for whether it serves any
  8. % particular purpose or works at all, unless he says so in writing.  Refer
  9. % to the Ghostscript General Public License for full details.
  10. %
  11. % Everyone is granted permission to copy, modify and redistribute
  12. % Ghostscript, but only under the conditions described in the Ghostscript
  13. % General Public License.  A copy of this license is supposed to have been
  14. % given to you along with Ghostscript so you can know your rights and
  15. % responsibilities.  It should be in a file named COPYING.  Among other
  16. % things, the copyright notice and this notice must be preserved on all
  17. % copies.
  18.  
  19. % viewpcx.ps
  20. % Display a PCX file.
  21. % Requires the Level 2 `image' operator (to handle variable pixel widths).
  22. % If SCALE is defined, maps input pixels to output pixels with that scale;
  23. % if SCALE is undefined, scales the image to fit the page.
  24. % ****NOTE: Requires RLE compression; does not handle multi-plane
  25. % ****images with palette.
  26.  
  27. /get2                % <string> <index> get2 <int>
  28.  { 2 copy get 3 1 roll 1 add get 8 bitshift add
  29.  } bind def
  30. /dsproc
  31.  { df s readstring pop        % s gets filled in
  32.    s1 () ne { df s1 readstring pop pop } if % discard padding bytes
  33.  } def                % don't bind, must be writable
  34. /viewpcx            % <filename> viewpcx -
  35.  { 100 dict begin
  36.    /fname 1 index def
  37.    /f exch (r) file def
  38.         % Read and unpack the header.
  39.    /header f 128 string readstring pop def
  40.    /version header 1 get def
  41.    /bpp header 3 get def
  42.    /w header 8 get2 header 4 get2 sub 1 add def
  43.    /h header 10 get2 header 6 get2 sub 1 add def
  44.    /nplanes header 65 get def
  45.    /bpl header 66 get2 def
  46.    /palinfo header 68 get2 def
  47.    /nbits bpp nplanes mul def
  48.    version 5 eq
  49.     { nbits 8 le
  50.        { /cspace
  51.        [/Indexed   /DeviceRGB   1 bpp bitshift 1 sub
  52.      f fileposition
  53.      1 nbits bitshift 3 mul string
  54.      fname status pop pop pop exch pop
  55.      1 index length sub f exch setfileposition
  56.      f exch readstring pop
  57.      exch f exch setfileposition
  58.        ] def
  59.      /decode [0 cspace 2 get] def
  60.        }
  61.        { /cspace /DeviceRGB def
  62.      /decode [0 1 0 1 0 1] def
  63.        }
  64.       ifelse
  65.     }
  66.     { /cspace
  67.     [/Indexed   /DeviceRGB   1 bpp bitshift 1 sub
  68.      header 16 1 nbits bitshift 16 min 3 mul getinterval
  69.     ] def
  70.       /decode [0 cspace 2 get] def
  71.     }
  72.    ifelse
  73.         % Set up scaling.
  74.    /SCALE where
  75.     { pop
  76.     % Map pixels SCALE-for-1.  Assume orthogonal transformation.
  77.       w 1 0 dtransform add abs div SCALE mul
  78.       h 0 1 dtransform add abs div SCALE mul
  79.     }
  80.     {    % Scale the image (uniformly) to fit the page.
  81.       clippath pathbbox pop pop translate
  82.       pathbbox min exch pop exch pop ceiling
  83.       dup h w gt { w mul h div exch } { h mul w div } ifelse
  84.     }
  85.    ifelse scale
  86.         % Since the number of bytes per line is always even,
  87.         % it may not match the width specification.
  88.    /wbpl w bpp mul 7 add 8 idiv def
  89.         % Define the data source procedure.
  90.    /s1 bpl wbpl sub string def
  91.    /df f /PCXDecode filter def
  92.    /dsource [ nplanes
  93.     { /dsproc load copyarray
  94.       dup 1 wbpl string put
  95.       cvx bind readonly
  96.     }
  97.    repeat ] def
  98.         % Construct the image dictionary.
  99.    20 dict begin        % image dictionary
  100.      /ImageType 1 def
  101.      /Width w def
  102.      /Height h def
  103.      /ImageMatrix [w 0 0 h neg 0 h] def
  104.      /BitsPerComponent bpp def
  105.      /Decode decode def
  106.      /DataSource dsource dup length 1 gt
  107.       { /MultipleDataSources true def }
  108.       { 0 get }
  109.      ifelse def
  110.    currentdict end
  111.         % Finally, display the image.
  112.    cspace setcolorspace
  113.    image
  114.    showpage
  115.    df closefile
  116.    f closefile
  117.    end
  118.  } bind def
  119.  
  120. % If the program was invoked from the command line, run it now.
  121. [ shellarguments
  122.  { counttomark 1 ge
  123.     { ] { viewpcx } forall
  124.     }
  125.     { cleartomark
  126.       (Usage: gs -- viewpcx.ps filename.pcx ...\n) print
  127.       ( e.g.: gs -- viewpcx.ps my.pcx another.pcx\n) print flush
  128.     }
  129.    ifelse
  130.  }
  131.  { pop
  132.  }
  133. ifelse
  134.